<?php
class Create extends CI_Controller{
    public function __construct(){
        parent::__construct();
    }
    public function index(){
        echo "<h2>Hello Codeigniter Framework</h2>";
       // $data['title']="Hello 123";

        //$this->load->view("backend/create_project",$data);

         $this->load->Model("backend/Mcreateproject");
        $arr_project = $this->Mcreateproject->getAllProject();
        $temp['data']['project'] = $arr_project;

       // var_dump($temp);
        $this->load->view("backend/create_project", $temp);
    }


    public function addproject(){

            $add = array(
                    "name_project" => $this->input->post("full_name"),
                    "video_project"    => $this->input->post("linkvideo"),
                 );

            $this->load->Model("backend/Mcreateproject");
            if($this->Mcreateproject->insert_project($add)){

            }
    }

//list danh sach cac project
   public function getproject(){
        $this->load->Model("backend/Mcreateproject");
        $arr_project = $this->Mcreateproject->getAllProject();
        $temp['data']['project'] = $arr_project;

       // var_dump($temp);
        $this->load->view("backend/create_project", $temp);

   }   

   public function getprojectbyid(){
        $id =$_GET['id'];;

        $this->load->Model("backend/Mcreateproject");
        $arr_project = $this->Mcreateproject->getProjectByID($id);
        //$temp['data']['project'] = $arr_project;
        //tra ve json 
        echo(json_encode($arr_project));
   }    



     public function updateproject(){

        $name_project = $this->input->post('full_name');
        $video_project = $this->input->post('linkvideo');
        $id = $this->input->post('id');


        $params = array(
          'id' => $id,
          'name_project' =>  $name_project,
          'video_project' =>  $video_project,
        );      

        $this->load->Model("backend/Mcreateproject");
        $result = $this->Mcreateproject->update_ProjectByID($params);
        if($result=1){
            echo "done";
        }
        else{
            echo "notdone";
        }

     }
}